Option Explicit

Dim pw_ch1 As Integer
Dim pw_ch2 As Integer
Dim temp As Integer
Dim range As Single

Sub RcIntrepreter()
	Do
		pw_ch1 = PulseIn(17,1)
		pw_ch2 = PulseIn(18,1)
'Debug.Print Cstr(pw_ch1) & "  " & Cstr(pw_ch2)

		If (pw_ch1 < 920) Then
			rc_activate = FALSE
		ElseIf (pw_ch2 < 820) Then
			rc_activate = FALSE
		Else	
			rc_activate = TRUE	
			If (pw_ch2 > 1355) Then
				forward = TRUE
				reverse = FALSE
				If (pw_ch2 > 1720) Then
'Debug.Print "Forward Full"
					fb_power = FULL_PWR
				ElseIf (pw_ch2 > 1595) Then
'Debug.Print "Forward 3/4"
					fb_power = THR_QTR_PWR
				ElseIf (pw_ch2 > 1480) Then
'Debug.Print "Forward 1/2"
						fb_power = HALF_PWR
				Else 'If (pw_ch2 < 1479)
'Debug.Print "Forward 1/4"
					fb_power = QTR_PWR
				End If			
			ElseIf (pw_ch2 < 1330) Then
				reverse = TRUE
				forward = FALSE
				If (pw_ch2 > 1195) Then
'Debug.Print "Reverse 1/4"
					fb_power = QTR_PWR
				ElseIf (pw_ch2 > 1070) Then
'Debug.Print "Reverse 1/2"
					fb_power = HALF_PWR
				ElseIf (pw_ch2 > 945) Then
'Debug.Print "Reverse 3/4"
					fb_power = THR_QTR_PWR	
				Else 'If (pw_ch2 < 944) 
'Debug.Print "Reverse Full"
					fb_power = FULL_PWR
				End If
			Else
'Debug.Print "Neutral"
				fb_power = NO_PWR
				reverse = FALSE
				forward = FALSE
			End If
			If (pw_ch1 < 1375) Then
				right = TRUE
				left = FALSE
				If (pw_ch1 > 1295) Then
'Debug.Print "Right 1/4"
					lr_power = QTR_PWR
				ElseIf (pw_ch1 > 1170) Then
'Debug.Print "Right 1/2"
					lr_power = HALF_PWR
				ElseIf (pw_ch1 > 1045) Then
'Debug.Print "Right 3/4"
					lr_power = THR_QTR_PWR	
				Else 'If (pw_ch1 < 1044) 
'Debug.Print "Right Full"
					lr_power = FULL_PWR
				End If
			ElseIf (pw_ch1 > 1400) Then
				left = TRUE
				right = FALSE
				If (pw_ch1 > 1775) Then
'Debug.Print "Left Full"
					lr_power = FULL_PWR
				ElseIf (pw_ch1 > 1650) Then
'Debug.Print "Left 3/4"
					lr_power = THR_QTR_PWR
				ElseIf (pw_ch1 > 1525) Then
'Debug.Print "Left 1/2"
					lr_power = HALF_PWR	
				Else 'If (pw_ch1 <= 1524) 
'Debug.Print "Left 1/4"
					lr_power = QTR_PWR
				End If
			Else
'Debug.Print "Center"
				lr_power = NO_PWR
				left = FALSE
				right = FALSE	
			End If			
		End If
		Call Sleep(0.5)
	Loop
End Sub